<?php

namespace common\models\DAO;

use Yii;

/**
 * This is the model class for table "mx_product_thumb".
 *
 * @property integer $id
 * @property integer $productID
 * @property string $thumb
 * @property integer $createTime
 * @property integer $isCover
 */
class ProductThumb extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mx_product_thumb';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['productID', 'createTime', 'isCover'], 'integer'],
            [['thumb'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'productID' => '产品ID',
            'thumb' => '图片地址',
            'createTime' => '添加时间',
            'isCover' => '是否为封面',
            'title' => '产品名称',
        ];
    }

    public function scenarios()
    {
        return [
            'default' => [],
            'add'   => ['productID','thumb'],
            'edit'  => ['productID','thumb'],
        ];
    }

    public function getProduct()
    {
        return $this->hasOne(Product::className(), ['id' => 'productID']);
    }

    public function beforeSave($insert)
    {
        if ($insert) {
            $this->createTime = time();
            $this->isCover = 0;

        }
        


        return parent::beforeSave($insert);
    }
}
